<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Migrating from GnomeColorPicker to GtkColorButton</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GTK+ 2 Reference Manual">
<link rel="up" href="migrating.html" title="Part IV. Migrating from Previous Versions of GTK+">
<link rel="prev" href="gtk-migrating-GtkAboutDialog.html" title="Migrating from GnomeAbout to GtkAboutDialog">
<link rel="next" href="gtk-migrating-GtkAssistant.html" title="Migrating from GnomeDruid to GtkAssistant">
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="gtk-migrating-GtkAboutDialog.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="migrating.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GTK+ 2 Reference Manual</th>
<td><a accesskey="n" href="gtk-migrating-GtkAssistant.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="gtk-migrating-GtkColorButton"></a>Migrating from GnomeColorPicker to GtkColorButton</h2></div></div></div>
<p>
    Since version 2.6, GTK+ provides the <a class="link" href="GtkColorButton.html" title="GtkColorButton"><span class="type">GtkColorButton</span></a>
    widget as a replacement for the <span class="structname">GnomeColorPicker</span> 
    widget in the libgnomeui library.
  </p>
<p>
   Porting an application from <span class="structname">GnomeColorPicker</span> to 
   <span class="structname">GtkColorButton</span> is very simple. 
   <span class="structname">GtkColorButton</span> doesn't support dithering 
   (since it is rarely needed on modern hardware), and it doesn't have 
   setters and getters to set the color from floating point or integer 
    components. So instead of
   </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="usertype">guint</span><span class="normal"> red</span><span class="symbol">,</span><span class="normal"> green</span><span class="symbol">,</span><span class="normal"> blue</span><span class="symbol">,</span><span class="normal"> alpha</span><span class="symbol">;</span>
<span class="comment">/* ... */</span>
<span class="function">gnome_color_picker_set_i8</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">color_picker</span><span class="symbol">,</span><span class="normal"> red</span><span class="symbol">,</span><span class="normal"> green</span><span class="symbol">,</span><span class="normal"> blue</span><span class="symbol">,</span><span class="normal"> alpha</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>   
   you have to write
   </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="usertype">GdkColor</span><span class="normal"> color</span><span class="symbol">;</span>

<span class="normal">color</span><span class="symbol">.</span><span class="normal">red </span><span class="symbol">=</span><span class="normal"> red </span><span class="symbol">&lt;&lt;</span><span class="normal"> </span><span class="number">8</span><span class="symbol">;</span>
<span class="normal">color</span><span class="symbol">.</span><span class="normal">green </span><span class="symbol">=</span><span class="normal"> green </span><span class="symbol">&lt;&lt;</span><span class="normal"> </span><span class="number">8</span><span class="symbol">;</span>
<span class="normal">color</span><span class="symbol">.</span><span class="normal">blue </span><span class="symbol">=</span><span class="normal"> blue </span><span class="symbol">&lt;&lt;</span><span class="normal"> </span><span class="number">8</span><span class="symbol">;</span>
<span class="function"><a href="GtkColorButton.html#gtk-color-button-set-color">gtk_color_button_set_color</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">color_picker</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">color</span><span class="symbol">);</span>
<span class="function"><a href="GtkColorButton.html#gtk-color-button-set-alpha">gtk_color_button_set_alpha</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">color_picker</span><span class="symbol">,</span><span class="normal"> alpha </span><span class="symbol">&lt;&lt;</span><span class="normal"> </span><span class="number">8</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>   
  and similarly for the setters taking other number formats. For 
  <code class="function"><code class="function">gnome_color_picker_set_i16()</code></code> no conversion is needed, 
  for <code class="function"><code class="function">gnome_color_picker_set_d()</code></code>, you need to convert 
  the color components like this:
   </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="normal">color</span><span class="symbol">.</span><span class="normal">red </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#guint16">guint16</a></span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">red </span><span class="symbol">*</span><span class="normal"> </span><span class="number">65535.0</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> </span><span class="number">0.5</span><span class="symbol">);</span>
<span class="normal">color</span><span class="symbol">.</span><span class="normal">green </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#guint16">guint16</a></span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">green </span><span class="symbol">*</span><span class="normal"> </span><span class="number">65535.0</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> </span><span class="number">0.5</span><span class="symbol">);</span>
<span class="normal">color</span><span class="symbol">.</span><span class="normal">blue </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#guint16">guint16</a></span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">blue </span><span class="symbol">*</span><span class="normal"> </span><span class="number">65535.0</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> </span><span class="number">0.5</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>   
  </p>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.18</div>
</body>
</html>